<?php
/**
 * Created by PhpStorm.
 * Email: 1194008361@qq.com
 * User:liaosp.top
 * Date: 2018/9/8
 * Time: 15:23
 */

namespace core;
use core\lib\route\Route;

class Thinksp
{
    static public function run()
    {
        try {
            $route= Route::selectRouteModel();
            $controller = $route->controller;
            $action = $route->action;
            $file = APP . 'Controller/' . $controller . '.php';
            $controllerClass = '\\' . MODULE . '\\Controller\\' . $controller;
            if (is_file($file)) {
                require_once $file;
                $class = new $controllerClass();
                if(!method_exists($class,$action)){
                    error('not find action');
                }else{
                    $class->$action();
                }
            } else {
                error('not find controller');
            }
        } catch (\Exception $exception) {
               error('framework error reson:'.$exception->getMessage());
        }
    }

    static public function load($class)
    {
        //自动加载库
        //   core\Route
        $class = str_replace('\\', '/', $class);
        $file = THINKSP . '/' . $class . '.php';
        if (is_file($file)) {
            require_once $file;
        } else {
           echo "23333";
        }
    }
}
